# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
# -*- coding: UTF-8 -*-


import argparse
import json
import os

from mqtt_client import MqttThread
from netty_client import NettyThread
from t2_client import T2Thread

from mqtt_client_testss import MqttThread_testss

if __name__ == '__main__':

    if os.path.exists(r'./boxlist.txt'):
        os.remove(r'./boxlist.txt')

    # 互斥参数
    parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]')
    parser.add_argument('-g', '--guibox', action='store_true', help='充电柜启动脚本')
    parser.add_argument('-c', '--chapai', action='store_true', help='充电插排启动脚本')
    parser.add_argument('-n', '--netty', action='store_true', help='充电桩启动脚本')
    parser.add_argument('-nb', '--nettybox', action='store_true', help='netty 充电柜启动脚本')
    parser.add_argument('-t', '--t2', action='store_true', help='道闸启动脚本')
    parser.add_argument('-v', '--version', action='store_true', help='系统版本')
    parser.add_argument('-ctestss', '--chapaitestss', action='store_true', help='testss充电插排启动脚本')

    args = parser.parse_args()  # 获取所有参数


    if args.version:
        #   读取配置文件
        with open('./config.json', 'r', encoding='utf-8')as fp:
            json_data = fp.read()
            json_data = json.loads(json_data)
            version = json_data['app']['version']['code']
            print("Current Verson:{version}")

    elif args.guibox:
        print(args.guibox)
        # 打开柜 mng 列表，线程启动
        with open('./mqtt_box.txt', 'r', encoding='utf-8') as fp:
            json_data = fp.readlines()
            for line in json_data:
                line = line.strip('\n')
                client_thread = MqttThread(line)
                client_thread.start()
    elif args.chapai:
        print(args.chapai)
        #  打开插排mng 列表，线程启动
        with open('./mqtt_mng.txt', 'r', encoding='utf-8') as fp:
            json_data = fp.readlines()
            for line in json_data:
                line = line.strip('\n')
                client_thread = MqttThread(line)
                client_thread.start()

    elif args.netty:
        print(args.netty)
        # 打开netty 列表，线程启动
        with open('./netty_mng.txt', 'r', encoding='utf-8') as fp:
            json_data = fp.readlines()
            for line in json_data:
                line = line.strip('\n')
                client_thread = NettyThread(line)
                client_thread.start()


    elif args.nettybox:
        print(args.netty)
        with open('./netty_box.txt', 'r', encoding='utf-8') as fp:
            json_data = fp.readlines()
            for line in json_data:
                line = line.strip('\n')
                client_thread = NettyThread(line)
                client_thread.start()
    elif args.t2:
        print(args.t2)
        with open('./t2_mng.txt', 'r', encoding='utf-8') as fp:
            json_data = fp.readlines()
            for line in json_data:
                line = line.strip('\n')
                client_thread = T2Thread(line)
                client_thread.start()

    elif args.chapaitestss:
        print(args.chapaitestss)
        with open('./mqtt_cp_testss.txt', 'r', encoding='utf-8') as fp:
            json_data = fp.readlines()
            for line in json_data:
                line = line.strip('\n')
                client_thread = MqttThread_testss(line)
                client_thread.start()
    else:
        print('*' * 50)
        print('请选择对应的参数执行，-h查询参数列表')
        print('*' * 50)
